package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.TempRequest;
import com.sc.nft.admin.request.UserWithCollectionRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.TempCollectionHoldings;
import com.sc.nft.entity.vo.UserWithCollectionSimpleVO;
import com.sc.nft.service.TempCollectionHoldingsService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 朱梦晨
 * @Description: 用户藏品持仓
 * @date 2024-08-05
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/temp/collectionHoldings")
@Api(tags="用户藏品持仓导出模块")
public class TempCollectionHoldingsController {

    private final TempCollectionHoldingsService tempCollectionHoldingsService;


    @PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户藏品持仓导出-品牌孵化-自由市场", notes = "用户藏品持仓导出-品牌孵化-自由市场", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempCollectionHoldingsBrandIncubation(@Valid @RequestBody UserWithCollectionRequest userWithCollectionRequest){
        return Result.success(tempCollectionHoldingsService.saveTempCollectionHoldings(userWithCollectionRequest.getMarketType()));
    }


    @PostMapping(value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户藏品持仓导出-下载", notes = "用户藏品持仓导出-下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<UserWithCollectionSimpleVO>> findCollectionHoldingsBrandIncubationList(@Valid @RequestBody TempRequest request){
        List<TempCollectionHoldings> tempCollectionHoldingsList = tempCollectionHoldingsService.findTempCollectionHoldingsList(request.getExportRecordsId());
        List<UserWithCollectionSimpleVO> userWithCollectionSimpleVOS = BeanUtil.copyToList(tempCollectionHoldingsList, UserWithCollectionSimpleVO.class);
        return Result.success(userWithCollectionSimpleVOS);
    }






}
